package com.learn.api.gateway.filters;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author lwt<br>
 * @description <br>
 * @date 2020/8/17
 */
@Slf4j
public class GatewayTestFilter implements GatewayFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("GatewayTestFilter前置逻辑--pre");
        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
            log.info("GatewayTestFilter后置逻辑--post");
        }));
    }

    /*
     *过滤器存在优先级，order越大，优先级越低
     */
    @Override
    public int getOrder() {
        return 0;
    }
}
